package com.cskaoyan.market.service.Impl;

import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.db.domain.MarketSearchHistoryExample;
import com.cskaoyan.market.db.mapper.MarketSearchHistoryMapper;
import com.cskaoyan.market.service.MarketHistoryService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 付诚
 * @Date: 2024/5/6 21:27
 * @Description:
 */
@Service
public class MarketHistoryServiceImpl implements MarketHistoryService {

    @Autowired
    private MarketSearchHistoryMapper marketHistoryMapper;
    @Override
    public List<MarketSearchHistory> list(Integer page, Integer limit, String userId, String keywork, String sort, String order) {

        MarketSearchHistoryExample marketHistoryExample = new MarketSearchHistoryExample();
        marketHistoryExample.setOrderByClause(sort + " " + order);
        MarketSearchHistoryExample.Criteria criteria = marketHistoryExample.createCriteria();
        if (!StringUtils.isEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.parseInt(userId));
        }
        if (!StringUtils.isEmpty(keywork)) {
            criteria.andKeywordLike("%" + keywork + "%");
        }

        //两个参数：当前页；每页数量
        PageHelper.startPage(page, limit);

        List<MarketSearchHistory> marketHistoryList = marketHistoryMapper.selectByExample(marketHistoryExample);

        return marketHistoryList;
    }
}
